<?php

namespace app\controllers;

use RedLock\RedLock;

class Test2Controller extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionRed() 
    {
        $time = microtime();
        $servers = [
            ['redis', 6379, 0.01],
            ['redis1', 6379, 0.01],
            ['redis2', 6379, 0.01],
            ['redis3', 6379, 0.01],
            ['redis4', 6379, 0.01],
        ];

        $redLock = new RedLock($servers);
        // $lock = $redLock->lock('my_resource_name', 10000);
        // return "'" . ((microtime() - $time)) . "'";
        $ii = 10;
        while ($ii--) {
            $lock = $redLock->lock('test', 1000);

            if ($lock) {
                print_r($lock);
            } else {
                print "Lock not acquired\n";
            }
        }

        return $time;
    }

}
